package com.ndp.fb.rdb.db.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.ndp.fb.rdb.api.ThirdPicAutoAuditRdbService;
import com.ndp.fb.rdb.db.DaoTemplate;
import com.ndp.fb.rdb.db.impl.mapper.DefaultRowMapper;
import com.ndp.fb.rdb.model.ThirdPicAutoAudit;

import java.util.List;

/**
 * Created by 15129 on 2015/10/20.
 */
@Service
public class ThirdPicAutoAuditRdbServiceImpl extends DaoTemplate implements ThirdPicAutoAuditRdbService {

    @Override
    public Long save(final ThirdPicAutoAudit o) {
        return saveResultId(o);
    }

    @Override
    public List<ThirdPicAutoAudit> find()
    {
        return findAll(DefaultRowMapper.autoRowMapper(ThirdPicAutoAudit.class));
    }

    @Override
    public List<Long> findNoDeal()
    {
        String sql = "SELECT ad_set_id FROM t_thirdpic_auto_audit WHERE flag = 0 GROUP BY ad_set_id";
        return getJdbcTemplate().queryForList(sql, Long.class);
    }

    @Override
    public List<ThirdPicAutoAudit> findNoDealAd()
    {
        String sql = "SELECT * FROM t_thirdpic_auto_audit WHERE flag = 0";
        return getJdbcTemplate().query(sql, DefaultRowMapper.autoRowMapper(ThirdPicAutoAudit.class));
    }

    @Override
    public List<ThirdPicAutoAudit> findByAdSetId(Long adSetId)
    {
        String sql = "SELECT * FROM t_thirdpic_auto_audit WHERE ad_set_id=? AND flag = 0 ";
        return getJdbcTemplate().query(sql,new Object[]{adSetId}, DefaultRowMapper.autoRowMapper(ThirdPicAutoAudit.class));
    }

    @Override
    public void updateFlagByAdGroupId(Long adGroupId)
    {
        String sql = "UPDATE t_thirdpic_auto_audit set " +
                "flag=? " +
                "where ad_group_id=?";
        Object[] param = new Object[]{1, adGroupId};
        getJdbcTemplate().update(sql, param);
    }

}
